layui.use(['form', 'layer', 'table', 'laytpl'], function () {
	var $ = layui.jquery,
		table = layui.table;
	window.active = {
		reload: () => {
			table.reload("tableListTable");
		},
		edit: (data) => {
			popEdit(data, 'page/gameDial/edit.html', ["500px", "700px"])
		},
		editPrize: (data) => {
			popEdit(data, 'page/gameDial/editPrize.html', ["1000px", "650px"])
		},
		del: (data) => {
			popDelete(data.name, 'gameDial', {
				id: data.id,
				task_id: data.task_id,
			});
			active.reload()
		},
		stop:(data)=>{
			top.layer.confirm('确定停止抽奖？', {
				icon: 3,
				title: '提示信息'
			},
			async function (index) {
			top.layer.close(index);
			id=data.id;
			let res = await ajaxAsyncNoTip('gameDial/stop',{id},'POST');
			active.reload();
			})
		},
		searchAwards:(data)=>{
			let index = top.layer.open({
				title: '查看添加奖品',
				type: 2,
				area:  ["700px", "510px"],
				fixed: false, //不固定
				offset: '50px',
				maxmin: false,
				content: 'page/gameDial/searchAwards.html',
				success: async function(layero, index) {
					let cw = layero.find('iframe')[0].contentWindow;
					cw.parentData = data;//给子页面公共变量赋值，初始化数据
					cw.___popLayerIndex = index;
					var body = top.layer.getChildFrame('body', index);
					setTimeout(function() {
						top.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					}, 200)
				}
			})
		}
	}


	//表格外按钮操作
	$('.tableHead .layui-btn').on('click', function () {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	//表格按钮操作
	table.on('tool(tableList)', function (obj) {
		var type = obj.event;
		active[type] ? active[type].call(this, obj.data) : '';
	});

})